﻿using Application.AppSrevices;
using Application.CFFKService;
using Application.Dto;
using Application.IAppSrevices;
using AutoMapper;
using Domain.Entitys;
using Microsoft.AspNetCore.Mvc;

namespace UI.Controllers
{
    public class CPCController : Controller
    {
        private readonly IMapper mapper;
        private readonly ICPCService cPCService;

        public CPCController(ICPCService cPCService, IMapper mapper)
        {
            this.mapper = mapper;
            this.cPCService = cPCService;
        }

        [HttpGet]
        public IActionResult CPCAdd()
        {
            return View();
        }

        public IActionResult Index()
        {
            return View();
        }
        public IActionResult Index2()
        {
            return View();
        }
        public IActionResult CPCtian()
        {
            return View();
        }
        public IActionResult Index1()
        {
            return View();
        }

        /// <summary>
        /// 公共字段设置数据显示
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> CPCSelect(int pageIndex, int pageSize)
        {
            IEnumerable<CPC> cPCs = await cPCService.CPCselectAsync(pageIndex, pageSize);
            return Json(cPCs);
        }
        /// <summary>
        /// 查询数据总数
        /// </summary>
        /// <returns></returns>
        public IActionResult SelectCount()
        {
            int count = cPCService.SelectCount();
            return Json(count);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="cPCAdd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> CPCAdd(CPCAdd cPCAdd)
        {
            int zhi = await cPCService.CPCAddAsync(cPCAdd);
            return Json(zhi);
            /*if (zhi > 0)
            {
                return RedirectToAction("Index");
            }
            else
            {
                return RedirectToAction("CPCAdd");
            }*/
        }
        /// <summary>
        /// 公共属性设置删除
        /// </summary>
        /// <param name="cPCDelete"></param>
        /// <returns></returns>
        /// 
        [HttpDelete]
        public async Task<int> CPCDelete(CPCDelete cPCDelete)
        {
            //await cPCService.CPCDeleteAsync(cPCDelete);


            return await cPCService.CPCDeleteAsync(cPCDelete);

            /*  return Json(non);*/
        }

        public async Task<IActionResult> CPCSelecta(int pageIndex, int pageSize, string name)
        {
            IEnumerable<CPC> cPCs = await cPCService.CPCselectaAsync(pageIndex, pageSize, name);
            return Json(cPCs);

        }
        public IActionResult SelectCounta(string name)
        {
            int count = cPCService.SelectCounta(name);
            return Json(count);
        }

		public async Task<IActionResult> CPCFillAsyncCPC(string kind)
        {
            List<CPC> list = await cPCService.CPCFillAsync(kind);
            return Json(list);
        }

		/// <summary>
		/// 薪酬新增
		/// </summary>
		/// <param name="cPCAdd"></param>
		/// <returns></returns>
		public async Task<IActionResult> CPCtianz(CPCAdd cPCAdd)
        {
            //if (ModelState.IsValid) {
            cPCAdd.AttributeKind = "薪酬设置";
            int ren = await cPCService.CPCxianz(cPCAdd);
            if (ren > 0)
            {
                TempData["SSDadd"] = "添加成功";
                return RedirectToAction("Index2");
            }
            else
            {
                TempData["SSDadd"] = "添加失败";
                return RedirectToAction("SSDAdd");
            }
        }
    }
}
